package com.crm.service.impl.sys;

import com.crm.dao.mapper.sys.VersionUpgradeMapper;
import com.crm.model.entity.sys.VersionUpgrade;
import com.crm.model.entity.sys.VersionUpgradeExample;
import com.crm.service.sys.VersionUpgradeDbService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author luojie
 * @date 2021/6/10 9:56
 */
@Service
public class VersionUpgradeDbServiceImpl implements VersionUpgradeDbService {

    @Autowired
    private VersionUpgradeMapper versionUpgradeMapper;

    @Override
    public VersionUpgrade getVersionUpgrade(String sysId, String versionType) {
        VersionUpgradeExample versionUpgradeExample = new VersionUpgradeExample();
        VersionUpgradeExample.Criteria criteria = versionUpgradeExample.createCriteria();
        criteria.andSysIdEqualTo(sysId);
        criteria.andVersionTypeEqualTo(versionType);
        versionUpgradeExample.setOrderByClause("create_tm desc");
        List<VersionUpgrade> versionUpgrades = versionUpgradeMapper.selectByExample(versionUpgradeExample);
        if(versionUpgrades.size()>0){
            return versionUpgrades.get(0);
        }else{
            return null;
        }
    }

    @Override
    public Boolean addVersionInfo(VersionUpgrade versionUpgrade) {
        int num = versionUpgradeMapper.insertSelective(versionUpgrade);
        if(num>0){
            return true;
        }else {
            return false;
        }
    }
}
